//
//  WeiboMianNavController.swift
//  微博
//
//  Created by LH on 2017/5/23.
//  Copyright © 2017年 LH. All rights reserved.
//

import UIKit

class WeiboMianNavController: UINavigationController {

//重写铺设、方法  所有push动作都会调用此方法
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count>0 {
            viewController.hidesBottomBarWhenPushed=true;
            if let vc = viewController as? WeiboBaseViewController{
                
                var title = "返回"
                //判断控制器的级数
                if childViewControllers.count == 1 {
                    //title显示首页的标题
                    title = (childViewControllers.first?.title) ?? "返回"
                }
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 15, target: self, action: #selector(popToParent),isBack:true)
            }
        
        }
        
        
        super.pushViewController(viewController, animated: animated)
   
        
    }
    
    @objc fileprivate func popToParent(){
        popViewController(animated: true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的Navigationbar
        navigationBar.isHidden = true
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
